'''
Created on 27.7.2011

Kaskettaessa vaihtaa naytettavien tulitusarkkimoodien valilla

@author: gilead
'''

class ShowArcStatus(object):
    '''
    classdocs
    '''

    # oletetaan, etta tilat seuraavat toisiaan seuraavassa jarjestyksessa
    STATE_HIDEALL = 0
    STATE_SHOWONE = 1
    STATE_SHOWALL = 2

    def __init__(self, world, camMan):
        self.world = world
        self.camMan = camMan
        self.hideAll()
    
    def changeState(self):
        if self.state == ShowArcStatus.STATE_HIDEALL:
            self.showOne()
        elif self.state == ShowArcStatus.STATE_SHOWONE:
            self.showAll()
        elif self.state == ShowArcStatus.STATE_SHOWALL:
            self.hideAll()
    
    def showOne(self):
        # naytetaan valitun aluksen kaikkien turrettien arkit
        ship = self.camMan.focusShip
        if ship != None:
            for shipchild in ship.getChildren():
                turret = shipchild.getPythonTag('Turret')
                if turret != None:
                    arc = turret.getArc()
                    if arc != None:
                        arc.show()
        self.state = ShowArcStatus.STATE_SHOWONE
        
    def hideAll(self):
        # piilotetaan kaikkien alusten kaikkien turrettien arkit
        # TODO: tassa voisi periaatteessa kayttaa findAllMatches:ia
        for worldchild in self.world.getChildren():
            ship = worldchild.getPythonTag('Ship')
            if ship != None:
                for shipchild in ship.getChildren():
                    turret = shipchild.getPythonTag('Turret')
                    if turret != None:
                        arc = turret.getArc()
                        if arc != None:
                            arc.hide()
        self.state = ShowArcStatus.STATE_HIDEALL
    def showAll(self):
        # naytetaan kaikkien alusten kaikkien turrettien arkit
        # TODO: tassa voisi periaatteessa kayttaa findAllMatches:ia
        for worldchild in self.world.getChildren():
            ship = worldchild.getPythonTag('Ship')
            if ship != None:
                for shipchild in ship.getChildren():
                    turret = shipchild.getPythonTag('Turret')
                    if turret != None:
                        if turret != None:
                            arc = turret.getArc()
                            if arc != None:
                                arc.show()
        self.state = ShowArcStatus.STATE_SHOWALL